package com.dongdongshop.service.impl;

import com.dk.util.PageResult;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbBrandExample;
import com.dongdongshop.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
//品牌管理
@DubboService
@Service
public class BrandServiceimpl  implements BrandService {


    @Autowired
    TbBrandMapper tm;

    //分页查询所有
    @Override
    public PageResult getall(Integer pagenum, Integer pagesize) {
        PageHelper.startPage(pagenum,pagesize);
        List<TbBrand> ls = tm.selectByExample(null);
        PageInfo info=new PageInfo(ls);
        PageResult p=new PageResult(pagenum,pagesize,info.getList(),info.getTotal());


        return p;
    }

    //增加
    @Override
    public int addbrand(TbBrand tb) {
        return  tm.insertSelective(tb);

    }

    //修改回显
    @Override
    public TbBrand byid(Long id) {
        return tm.selectByPrimaryKey(id);
    }

    //修改
    @Override
    public int updatebrand(TbBrand tb) {
        return tm.updateByPrimaryKey(tb);
    }

    //删除
    @Override
    public int deleteid(Long id) {
        return tm.deleteByPrimaryKey(id);
    }

    //状态码方式
    @Override
    public List<TbBrand> getlist() {
        return tm.selectByExample(null);
    }


    //状态码分页模糊查询
    @Override
    public PageResult selectfen(Integer pagenum, Integer pagesize, String name) {
        PageHelper.startPage(pagenum,pagesize);
        TbBrandExample te=new TbBrandExample();
        if(name!=null&&!"".equals(name)){
            TbBrandExample.Criteria criteria = te.createCriteria();
            criteria.andNameEqualTo("%"+name+"%");
        }
        List<TbBrand> ls = tm.selectByExample(te);
        PageInfo p=new PageInfo(ls);
        PageResult pageResult=new PageResult(pagenum,pagesize,p.getList(),p.getTotal());
        return pageResult;
    }
}
